package com.jz.community.moduleexpress.express.task;

import android.app.Activity;

import com.jz.community.basecomm.net.OkHttpUtil;
import com.jz.community.basecomm.task.ITaskCallbackListener;
import com.jz.community.basecomm.task.RxTask;
import com.jz.community.basecomm.utils.BaseSpUtils;
import com.jz.community.basecomm.utils.JsonUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.commview.view.widget.ProgressDialogManager;
import com.jz.community.moduleexpress.express.baseConstant.ExpressConstant;
import com.jz.community.moduleexpress.express.info.ExpressInfoBean;
import com.jz.community.moduleexpress.express.info.baseInfo.BaseEntity;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Tony.Fan on 2018/6/25 17:47
 * <p>
 */
public class GetExpressSignTask extends RxTask<String, Integer, BaseEntity> {

    private Activity activity;
    private ITaskCallbackListener taskListener;

    public GetExpressSignTask(Activity activity,
                              ITaskCallbackListener taskListener) {
        super(activity);
        this.activity = activity;
        this.taskListener = taskListener;
    }

    @Override
    protected BaseEntity doInBackground(String... params) {
        // 执行请求
        String result = OkHttpUtil.get(ExpressConstant.EXPRESS_LIST, getParam(params[0]));
        BaseEntity info = null;
        if (!Preconditions.isNullOrEmpty(result)) {
            info = JsonUtils.parseObject(result, BaseEntity.class);
        }
        return info;
    }

    @Override
    protected void onPostExecute(BaseEntity result) {
        // 执行结果回调函数
        taskListener.doTaskComplete(result);
        ProgressDialogManager.dismissProgressDialog();
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        ProgressDialogManager.showDialog(activity);
        super.onPreExecute();
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }

    /**
     * 获取请求所需的参数
     *
     * @param
     * @return
     */
    private HashMap<String, Object> getParam(String id) {

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("session", BaseSpUtils.getInstance().getAccess_token(activity));
        hashMap.put("user_type", "sqr");
        hashMap.put("terminal", "1");
        hashMap.put("sign_type", "3");
        hashMap.put("id", id);
        return hashMap;
    }
}